package com.hc.tenant.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hc.common.log.annotation.Log;
import com.hc.common.log.enums.BusinessType;
import com.hc.common.security.annotation.PreAuthorize;
import com.hc.tenant.domain.RobotCommand;
import com.hc.tenant.service.IRobotCommandService;
import com.hc.common.core.web.controller.BaseController;
import com.hc.common.core.web.domain.AjaxResult;
import com.hc.common.core.utils.poi.ExcelUtil;
import com.hc.common.core.web.page.TableDataInfo;

/**
 * 机器人命令管理Controller
 * 
 * @author yongjainz
 * @date 2021-03-26
 */
@RestController
@RequestMapping("/command")
public class RobotCommandController extends BaseController
{
    @Autowired
    private IRobotCommandService robotCommandService;

    /**
     * 查询机器人命令管理列表
     */
    @PreAuthorize(hasPermi = "tenant:command:list")
    @GetMapping("/list")
    public TableDataInfo list(RobotCommand robotCommand)
    {
        startPage();
        List<RobotCommand> list = robotCommandService.selectRobotCommandList(robotCommand);
        return getDataTable(list);
    }

    /**
     * 导出机器人命令管理列表
     */
    @PreAuthorize(hasPermi = "tenant:command:export")
    @Log(title = "机器人命令管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RobotCommand robotCommand) throws IOException
    {
        List<RobotCommand> list = robotCommandService.selectRobotCommandList(robotCommand);
        ExcelUtil<RobotCommand> util = new ExcelUtil<RobotCommand>(RobotCommand.class);
        util.exportExcel(response, list, "command");
    }

    /**
     * 获取机器人命令管理详细信息
     */
    @PreAuthorize(hasPermi = "tenant:command:query")
    @GetMapping(value = "/{commandId}")
    public AjaxResult getInfo(@PathVariable("commandId") Integer commandId)
    {
        return AjaxResult.success(robotCommandService.selectRobotCommandById(commandId));
    }

    /**
     * 新增机器人命令管理
     */
    @PreAuthorize(hasPermi = "tenant:command:add")
    @Log(title = "机器人命令管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RobotCommand robotCommand)
    {
        return toAjax(robotCommandService.insertRobotCommand(robotCommand));
    }

    /**
     * 修改机器人命令管理
     */
    @PreAuthorize(hasPermi = "tenant:command:edit")
    @Log(title = "机器人命令管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RobotCommand robotCommand)
    {
        return toAjax(robotCommandService.updateRobotCommand(robotCommand));
    }

    /**
     * 删除机器人命令管理
     */
    @PreAuthorize(hasPermi = "tenant:command:remove")
    @Log(title = "机器人命令管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commandIds}")
    public AjaxResult remove(@PathVariable Integer[] commandIds)
    {
        return toAjax(robotCommandService.deleteRobotCommandByIds(commandIds));
    }
}
